package net.bioteam.perl5;

import java.util.LinkedList;
import java.util.List;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;

public class Perl5ScriptEngineFactory implements ScriptEngineFactory
{

	List<String> extensions = new LinkedList<String>();
	List<String> mimeTypes = new LinkedList<String>();
	List<String> names = new LinkedList<String>();
	{
		extensions.add("pl");
		mimeTypes.add("text/cgi");
		names.add("perl");

	}

	public String getEngineName()
	{
		return "simple perl hook for script engine";
	}

	public String getEngineVersion()
	{
		return "0.01";
	}

	public List<String> getExtensions()
	{
		return extensions;
	}

	public String getLanguageName()
	{
		return "perl";
	}

	public String getLanguageVersion()
	{
		return "5.0";
	}

	public String getMethodCallSyntax(String obj, String m, String... args)
	{
		throw new UnsupportedOperationException("not implemented");
	}

	public List<String> getMimeTypes()
	{
		return mimeTypes;
	}

	public List<String> getNames()
	{
		return names;
	}

	public String getOutputStatement(String toDisplay)
	{
		return "print '"+toDisplay+"'";
	}

	public Object getParameter(String key)
	{
		if (key.equals(ScriptEngine.ENGINE))
		{

			this.getScriptEngine();
		} else if (key.equals(ScriptEngine.ENGINE_VERSION))
		{
			this.getEngineVersion();
		} else if (key.equals(ScriptEngine.NAME))
		{
			this.getEngineName();

		} else if (key.equals(ScriptEngine.LANGUAGE))
		{
			this.getLanguageName();
		} else if (key.equals(ScriptEngine.LANGUAGE_VERSION))
		{
			this.getLanguageName();

		} else if (key.equals("THREADING"))
		{
			return "STATELESS";
		} 
			return null;
		

	}

	public String getProgram(String... statements)
	{
		throw new UnsupportedOperationException("not implemented");
	}

	public ScriptEngine getScriptEngine()
	{
		Perl5ScriptEngine engine=new Perl5ScriptEngine();
		engine.fac=this;
		return engine;
	}

}
